
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="portlet box blue">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-gift"></i>产品类型
		</div>
	</div>
	<div class="portlet-body form">
		<form id="productTypeForm" class="form-horizontal form-bordered"
			action="/productType/save" method="post">
			<div class="form-group">
				<label class="col-md-3 control-label">名称:</label>
				<div class="col-md-4">
					<input type="text" name="name" id="name" class="form-control"
						value="${productType.name}" maxlength="45" />
				</div>
			</div>
			<%-- <div class="form-group">
				<label class="col-md-3 control-label">编码:</label>
				<div class="col-md-4">
					<input type="text" name="code" class="form-control"
						value="${productType.code}" maxlength="45" />
				</div>
			</div> --%>
			<div class="form-group">
				<label class="col-md-3 control-label">描述:</label>
				<div class="col-md-4">
					<input type="text" name="desc" id="desc" class="form-control"
						value="${productType.desc}" maxlength="45" />
				</div>
			</div>
			<%-- <div class="form-group">
				<label class="col-md-3 control-label">上级用品名称:</label>
				<div class="col-md-4">
					<select class="form-control">
						<c:forEach items="${productTypes }" var="product" varStatus="vs">
							<option value="${product.id }">${product.name }</option>
						</c:forEach>
					</select>
					 <input type="text" name="parent" class="form-control" value="${productType.parent}"  maxlength="10"/>

				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">分类:</label>
				<div class="col-md-4">
					<input type="text" name="sort" class="form-control"
						value="${productType.sort}" maxlength="10" />
				</div>
			</div> --%>
			<div class="form-actions">
				<div class="col-md-9 col-md-offset-3">
					<button type="button" class="btn btn-primary"
						onclick="saveProductType(this)">
						<spring:message code="btn.save"></spring:message>
					</button>
					<button type="reset" class="btn btn-default" onclick="cancel()">
						<spring:message code="btn.return"></spring:message>
					</button>
				</div>
			</div>
			<input type="hidden" name="id" id="id" value="${productType.id}">
			<input type="hidden" name="parent" id="parent"
				value="${productType.parent}">
		</form>
	</div>
</div>
<script type="text/javascript"
	src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
	function saveParentMenu() {
		var nodes = $.fn.zTree.getZTreeObj("menuTree").getSelectedNodes();
		if (nodes[0].id != $('#id').val()) {
			$('#parentId').val(nodes[0].id);
			$('#parentName').val(nodes[0].name);
			// 隐藏弹窗
			$('#menuModal').modal('hide');
		} else {
			alert('不能选择当前菜单');
		}
	}

	function saveProductType() {
		if ($('#name').val().trim() == "") {
			$('#name').val("");
			alert("产品类型名称不能为空");
			return false;
		}
		if ($('#productTypeForm').valid()) {
			//表单序列化
			/* var formData = new FormData($('#equipmentForm')[0]); */
			$.ajax({
				type : 'post',
				url : '<c:url value="/productType/save"></c:url>',
				data : $('#productTypeForm').serialize(),
				dataType : 'json',
				success : function(data) {
					alert(messages[data.result]);
					search();
					$(".panel-search").show();
				}
			});

		}
	}

	$(function() {
		$('#productTypeForm').validate();
	});
</script>